package com.suray.wcs.service.websocket;

import com.alibaba.fastjson.JSON;
import com.suray.commin.core.controller.ResponseData;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 * 重写编码器，使得websocket支持对象转json
 *
 * @author rbj
 */
public class ServerEncoder implements Encoder.Text<ResponseData> {
    @Override
    public void destroy() {

    }

    @Override
    public void init(EndpointConfig arg0) {

    }

    @Override
    public String encode(ResponseData responseData) throws EncodeException {
        return JSON.toJSONString(responseData);
    }

}
